Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/batching circuit gadgets #396

Merged

Conversation

nicholas-mainardi
Copy link
Contributor

This PR provides the gadgets necessary to build the batching query circuits, in particular:

Copy link
Collaborator

@nikkolasg nikkolasg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, long PR so i did what I could, overall seems LGTM to me ! I asked a few questions where it wasn't clear for me.
Thanks !

mp2-common/src/utils.rs Show resolved Hide resolved
row_path: MerklePathWithNeighborsGadget<ROW_TREE_MAX_DEPTH>,
index_path: MerklePathWithNeighborsGadget<INDEX_TREE_MAX_DEPTH>,
row_cells: &RowCells,
is_non_dummy_row: bool,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is confusing in the double negation way, can we use the flag as dummy_row: bool or even better, an enum ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's simpler to have this doubly-negated flag in circuit, but I can have the more intuitive version in the API and negate it in the assign function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 5787dc7

min_query_bound: &UInt256Target,
max_query_bound: &UInt256Target,
are_rows_tree_nodes: bool,
) -> (BoolTarget, BoolTarget) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comments to say what are the returned bools ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 5787dc7

Comment on lines 62 to 67
// if second_node_pred_in_range is true, and the predecessor of the second node was found in the path from
// such node to the root of the tree, then the hash of predecessor node will be placed in
// `second..predecessor_info.hash` by `MerklePathWithNeighborsGadget: therefore, we can check that `second`
// is consecutive of `first` by checking that `second.predecessor_info.hash` is the hash of the first node;
// otherwise, we cannot check right now that the 2 nodes are consecutive, and it necessarily means we have
// already done it before when checking that the successor of first node was the second node
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify a bit this for me please ?

  • if the successor of first node is not found, we'll check it later (from comments)
  • if predecessor of second node is not found, that means we checked it already in the first point ?
    do you mean either of these two conditions MUST be true at all times ? Can you tell me why quickly ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When both first and second are in the same tree, one of the conditions must be always true, I argued about this here.
Indeed, later in this method I compute also a flag either_is_in_path, which is true iff one of the 2 conditions is true, and I enforce this flag to be true if the 2 nodes are in the same tree.

Instead, both the conditions might be false if first and second doesn't belong to the same tree: for instance, if first is the last node in a rows tree, and second is the first node in another rows tree, then first has no successor, and second has no predecessor, so both the conditions will be false. However, in this case we don't need to bind successor of first with second, and vice versa, since the node belongs to different rows trees (we are doing other checks to enforce that the nodes are consecutive across rows trees), so it's not an issue to skip both these checks on successor/predecessor hash. Does it clarify the logic here?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, thanks !

mp2-common/src/group_hashing/mod.rs Show resolved Hide resolved
second_node_pred_in_range.target,
);
let range_flags_xor = b.arithmetic(
F::NEG_ONE + F::NEG_ONE,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

worth putting it in a constant ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in commit 5787dc7

Comment on lines 155 to 158
min_primary: &UInt256Target,
max_primary: &UInt256Target,
min_secondary: &UInt256Target,
max_secondary: &UInt256Target,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you precise whether those are from the query or just from a node ? I assume the query but would be nice to have clear context all the time when talking about min and max.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed in commit 5787dc7

/// This module contains gadgets to enforce whether 2 rows are consecutive
pub(crate) mod consecutive_rows;

/// Data structure containing the wires representing the data realted to the node of
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 5787dc7

verifiable-db/src/query/batching/row_chunk/mod.rs Outdated Show resolved Hide resolved
}

/// Data structure containing the `BoundaryRowNodeInfoTarget` wires for the nodes
/// realted to a given boundary row. In particular, it contains the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

related

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in commit 5787dc7

nicholas-mainardi and others added 4 commits November 13, 2024 12:06
This PR adds the circuits to prove queries in a batching fashion,
building up on the gadget introduced with previous PRs.
These circuits should allow to scale better when proving queries. In
terms of public parameters, these circuits will be currently available
only by enabling the feature `batching_circuits`; this is a temporary
solution to avoid including 2 different sets of circuits for the same
task, and we will remove this feature once we will assess whether it's
worthy to replace the existing query circuits with the batching ones.

---------

Co-authored-by: T <[email protected]>
@nikkolasg nikkolasg merged commit fcf3030 into feat/merkle-path-with-successor-gadget Jan 8, 2025
4 checks passed
@nikkolasg nikkolasg deleted the feat/batching_circuit_gadgets branch January 8, 2025 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants